#ifndef ______WARD___SLIDERBAR_H
#define ______WARD___SLIDERBAR_H


#include "uielement.h"
#include "driver.h"



class sliderBar : public uielement
{
	public:
		sliderBar(int x,int y,float l,float r,float s,int w = 75,int h = 20,int b = 2);

		void select() { }
		void left() { if(data-step < leftB) data = leftB; else data -= step; }
		void right() { if(data+step > rightB) data = rightB; else data += step; }
		void draw() {  drawEnabled(xpos, ypos); }
		void drawAt(int x, int y) { drawEnabled(x,y); }
		bool clicked(int x, int y) { clickX = x-xpos; return (((x >= xpos)&&(x <= xpos+width))&&((y >= (ypos+(height/100)))&&(y <= (ypos+(99*height/100))))); }
		void onClick() { 
			int n = ((rightB - leftB)/step); 

			if(n > 0){
				data = min(float(rightB-leftB),max((float)0,(float)(clickX / (width/n))));
			}
		}

		float getData() { return data + leftB; }
		void setData(float f) { data = max(float(0.0),float(f-leftB)); }
		void setLeft(float l) { leftB = l; }
		void setRight(float r) { rightB = r; }

	private:
		
		void drawEnabled(int x, int y);
		void drawDisabled();

		int border, width, height;
		float step;
		float leftB, rightB;
		int clickX;
};

#endif